package o;

import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.huawei.appgallery.downloadengine.api.SessionDownloadTask;
import com.huawei.appgallery.foundation.account.bean.UserSession;
import com.huawei.appgallery.foundation.application.pkgmanage.model.reserve.ReserveDbInfo;
import com.huawei.appgallery.foundation.application.pkgmanage.model.update.ApkUpgradeInfo;
import com.huawei.appgallery.foundation.service.common.protocol.AppDetailActivityProtocol;
import com.huawei.appgallery.foundation.service.common.protocol.AppDetailActivityProtocol.Request;
import com.huawei.appgallery.serverreqkit.api.bean.ResponseBean;
import com.huawei.appmarket.service.deamon.bean.DownloadHistory;
import com.huawei.appmarket.service.predownload.thread.PreDownloadManagerThread;
import com.huawei.appmarket.service.predownload.thread.PreDownloadManagerThread.ApkUpgradeInfoComparator;
import com.huawei.appmarket.service.predownload.thread.PreDownloadManagerThread.e;
import com.huawei.appmarket.service.reserve.game.bean.ReserveResponse;
import java.util.Comparator;
import java.util.List;
import o.dkb.d;
import o.ewm.n;

public class dqd extends dpn<Boolean, Boolean> implements e {
    protected /* synthetic */ Object ˋ(Context context, Object obj) throws InterruptedException {
        return ˎ(context, (Boolean) obj);
    }

    protected /* synthetic */ void ˏ(Context context, Object obj, Object obj2) throws InterruptedException {
        ˎ(context, (Boolean) obj, (Boolean) obj2);
    }

    protected /* synthetic */ Object ॱ(Context context) throws InterruptedException {
        return ˋ(context);
    }

    public dqd() {
        this.ˊ = "GameReserveDldTask";
    }

    public static void ॱ(String str, String str2) {
        dko o_dko = new dko();
        cjo appDetailActivityProtocol = new AppDetailActivityProtocol();
        Request request = new Request();
        request.ˋ(drj.ॱ(str2));
        appDetailActivityProtocol.ˏ(request);
        Intent ॱ = new cjm("appdetail.activity", appDetailActivityProtocol).ॱ(ContentManager.getInstant().getContext());
        ॱ.putExtra("activity_open_from_notification_flag", true);
        o_dko.ˊ(ॱ);
        o_dko.ˋ(ContentManager.getInstant().getContext().getString(n.ʾʻ, new Object[]{str}));
        o_dko.ˊ(ContentManager.getInstant().getContext().getString(n.ʾʽ));
        o_dko.ˏ(20160503);
        dkk.ˊ(ContentManager.getInstant().getContext(), o_dko).ˎ();
    }

    protected Boolean ˋ(Context context) {
        if (ejj.ˊ().ˎ()) {
            Logger.ˎ(this.ˊ, "child mode is open.");
            return Boolean.valueOf(false);
        }
        boolean z;
        if (((cdg) cdb.ॱ(cdg.class)).ˊ() > 0) {
            z = true;
        } else {
            z = false;
        }
        if (z) {
            edj ˋ = edh.ˋ(context);
            if (ˋ.ॱ || ˋ.ˎ > edl.ˏ().ˊ()) {
                return Boolean.valueOf(true);
            }
            Logger.ˎ(this.ˊ, "batteryStatus:" + ˋ.toString());
            return Boolean.valueOf(false);
        }
        Logger.ˎ(this.ˊ, "no game reserved");
        return Boolean.valueOf(false);
    }

    protected Boolean ˎ(Context context, Boolean bool) {
        if (bool == null || !bool.booleanValue()) {
            return Boolean.valueOf(false);
        }
        List ᐝ = ((cdg) cdb.ॱ(cdg.class)).ᐝ();
        Logger.ˎ("ScheduleRepeatService", this.ˊ + " execute:" + ᐝ.size());
        new PreDownloadManagerThread(context, ᐝ, this).ॱ();
        return Boolean.valueOf(true);
    }

    protected void ˎ(Context context, Boolean bool, Boolean bool2) {
    }

    public void ˏ() {
        Logger.ˎ(this.ˊ, "start game reserve dl");
    }

    public int ॱ() {
        return 3;
    }

    public Comparator<ApkUpgradeInfo> ˋ() {
        return new ApkUpgradeInfoComparator();
    }

    public boolean ˎ() {
        return true;
    }

    public void ˊ(@Nullable SessionDownloadTask sessionDownloadTask, @NonNull ApkUpgradeInfo apkUpgradeInfo, d dVar) {
        edw.ॱ(apkUpgradeInfo, sessionDownloadTask, "GameReserve", "gamedl_", 3, "wlanGameReserve", dVar);
    }

    public boolean ˋ(SessionDownloadTask sessionDownloadTask) {
        ReserveDbInfo ॱ = efg.ˋ().ॱ(sessionDownloadTask.ˊˊ());
        if (ॱ == null) {
            return false;
        }
        if (eff.ˊ().ˏ().ˊ(ॱ.ॱˊ())) {
            Logger.ˎ(this.ˊ, "game reserve from game center.local game center is support reserving game,so do not download by appmarket");
            return false;
        }
        cvt o_efc = new efc(UserSession.getInstance().getUserId());
        o_efc.ॱ(sessionDownloadTask.ˊˊ());
        o_efc.ˎ(-1);
        ResponseBean ॱ2 = cfw.ॱ(o_efc);
        if (!(ॱ2 instanceof ReserveResponse) || ॱ2.getResponseCode() != 0) {
            return false;
        }
        Logger.ˎ(this.ˊ, "QUERY RESERVE:responseCode:" + ॱ2.getResponseCode() + ",rtnCode:" + ॱ2.getRtnCode_());
        if (101001 == ॱ2.getRtnCode_()) {
            try {
                int parseInt = Integer.parseInt(ॱ.ᐝॱ());
            } catch (NumberFormatException e) {
                Logger.ˎ(this.ˊ, "versionCode NumberFormatException error:" + e.getMessage());
                boolean z = false;
            }
            PackageInfo ᐝ = ((cdg) cdb.ॱ(cdg.class)).ᐝ(sessionDownloadTask.ˊˊ());
            if (ᐝ == null || ᐝ.versionCode < r1) {
                return true;
            }
            Logger.ˎ(this.ˊ, "reserve app is installed, do not need download again, packageName: " + sessionDownloadTask.ˊˊ());
            return false;
        } else if (101006 != ॱ2.getRtnCode_() && 101007 != ॱ2.getRtnCode_()) {
            return false;
        } else {
            efb.ॱ().ˏ(sessionDownloadTask.ˊˊ());
            return false;
        }
    }

    public int ˊ(@NonNull SessionDownloadTask sessionDownloadTask) {
        DownloadHistory downloadHistory = new DownloadHistory(sessionDownloadTask);
        downloadHistory.ॱ();
        dsv.ॱ(downloadHistory);
        if (!cep.ˏ()) {
            ॱ(sessionDownloadTask.ʿ(), sessionDownloadTask.ˊˊ());
        }
        if (epv.ᐝ(ContentManager.getInstant().getContext())) {
            return 0;
        }
        return 3;
    }

    public void ˊ(int i) {
        Logger.ˎ(this.ˊ, "end game reserve dl:" + i);
    }

    public void ˊ(List<String> list) {
    }

    public void ʼ() {
    }
}
